package handler

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"shopping_07_28/api/request"
	"shopping_07_28/internal/model"
)

func AddOrder(c *gin.Context) {
	var req request.AddOrder
	var order model.Order

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	if req.Money == "0" {
		log.Println("订单忽略", req)
		return
	}

	order = model.Order{
		UserId: req.UserId,
		Money:  req.Money,
		Status: 0,
	}

	err := order.AddOrder()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "入库失败",
			"data": nil,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "入库成功",
		"data": order.CreatedAt,
	})

}

func ListOrder(c *gin.Context) {

}

func ListByErrOrder(c *gin.Context) {

}

func ListByUserOrder(c *gin.Context) {

}
